local thbattle__qiujingye_qiufeng = fk.CreateSkill {

  name = "thbattle__qiujingye_qiufeng",

  tags = {  },

}



thbattle__qiujingye_qiufeng:addEffect(fk.EventPhaseEnd, {
  prompt = "#thbattle__qiujingye_qiufeng",
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(thbattle__qiujingye_qiufeng.name) and target.phase == Player.Discard then
      local to_select_players = table.filter(player.room:getOtherPlayers(player), function(p)
        return not p:isNude()
      end)
      local ids = {}
      player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.toArea == Card.DiscardPile then
            for _, info in ipairs(move.moveInfo) do
              if player.room:getCardArea(info.cardId) == Card.DiscardPile then
                table.insertIfNeed(ids, info.cardId)
              end
            end
          end
        end
        return false
      end, Player.HistoryPhase)
      if #ids > 0 then
        event:setCostData(self, #ids)
        return #to_select_players > 0
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, thbattle__qiujingye_qiufeng.name, "#thbattle__qiujingye_qiufeng:::" .. event:getCostData(self))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = event:getCostData(self)
    local to_select_players = table.filter(room:getOtherPlayers(player), function(p)
      return not p:isNude()
    end)
    if #to_select_players > 0 then
      local target_players = room:askForChoosePlayers(player, table.map(to_select_players, Util.IdMapper), 1
      , math.min(num, #to_select_players), "#thbattle__qiujingye_qiufeng-choose_players",thbattle__qiujingye_qiufeng.name, true)
      if #target_players > 0 then
        for _, pid in ipairs(target_players) do
          local target_p = room:getPlayerById(pid)
          local choose_cid = room:askForCardChosen(player, target_p, "he", thbattle__qiujingye_qiufeng.name,
            "#thbattle__qiujingye_qiufeng-choose_card")
          room:throwCard(choose_cid, thbattle__qiujingye_qiufeng.name, target_p, player)
        end
      end
    end
  end,
})

return thbattle__qiujingye_qiufeng